/*
  ==============================================================================

  This is an automatically generated file created by the Jucer!

  Creation date:  4 Jun 2008 10:29:33 am

  Be careful when adding custom code to these files, as only the code within
  the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
  and re-saved.

  Jucer version: 1.11

  ------------------------------------------------------------------------------

  The Jucer is part of the JUCE library - "Jules' Utility Class Extensions"
  Copyright 2004-6 by Raw Material Software ltd.

  ==============================================================================
*/

//[Headers] You can add your own extra header files here...
#include "KetonalFormEditor.h"
//[/Headers]

#include "formElement.h"


//[MiscUserDefs] You can add your own user definitions and misc code here...
//[/MiscUserDefs]

//==============================================================================
formElement::formElement (KetonalFormEditor *_p, int i)
    : Component (T("formElement")),
      groupComponent (0),
      formFieldType (0),
      formFieldName (0),
      formFieldValue (0),
      removeFormElement (0)
{
    addAndMakeVisible (groupComponent = new GroupComponent (T("new group"),
                                                            T("Element")));
    groupComponent->setTextLabelPosition (Justification::centred);

    addAndMakeVisible (formFieldType = new ComboBox (T("Field Type")));
    formFieldType->setTooltip (T("Field Type"));
    formFieldType->setEditableText (false);
    formFieldType->setJustificationType (Justification::centredLeft);
    formFieldType->setTextWhenNothingSelected (String::empty);
    formFieldType->setTextWhenNoChoicesAvailable (T("(no choices)"));
    formFieldType->addItem (T("Input"), 1);
    formFieldType->addItem (T("ASK - Input"), 2);
    formFieldType->addItem (T("File"), 3);
    formFieldType->addListener (this);

    addAndMakeVisible (formFieldName = new TextEditor (T("Field Name")));
    formFieldName->setTooltip (T("Field Name"));
    formFieldName->setMultiLine (false);
    formFieldName->setReturnKeyStartsNewLine (false);
    formFieldName->setReadOnly (false);
    formFieldName->setScrollbarsShown (true);
    formFieldName->setCaretVisible (true);
    formFieldName->setPopupMenuEnabled (true);
    formFieldName->setColour (TextEditor::backgroundColourId, Colour (0xbeffffff));
    formFieldName->setColour (TextEditor::shadowColourId, Colour (0x0));
    formFieldName->setText (T("name"));

    addAndMakeVisible (formFieldValue = new TextEditor (T("Field Value")));
    formFieldValue->setTooltip (T("Field Value"));
    formFieldValue->setMultiLine (true);
    formFieldValue->setReturnKeyStartsNewLine (true);
    formFieldValue->setReadOnly (false);
    formFieldValue->setScrollbarsShown (true);
    formFieldValue->setCaretVisible (true);
    formFieldValue->setPopupMenuEnabled (true);
    formFieldValue->setColour (TextEditor::backgroundColourId, Colour (0xbeffffff));
    formFieldValue->setColour (TextEditor::shadowColourId, Colour (0x0));
    formFieldValue->setText (T("value"));

    addAndMakeVisible (removeFormElement = new ImageButton (T("Remove Element")));
    removeFormElement->setTooltip (T("Remove Element"));
    removeFormElement->setButtonText (T("new button"));
    removeFormElement->addButtonListener (this);

    removeFormElement->setImages (false, true, true,
                                  ImageCache::getFromMemory (listremove_png, listremove_pngSize), 0.5786f, Colour (0x0),
                                  ImageCache::getFromMemory (listremove_png, listremove_pngSize), 1.0000f, Colour (0x0),
                                  ImageCache::getFromMemory (listremove_png, listremove_pngSize), 1.0000f, Colour (0x38f7ff76));

    //[UserPreSize]
	shouldBeRemoved = false;
	parent = _p;
	index = i;
	formFieldName->setFont (Font(11));
	formFieldName->applyFontToAllText (Font(11));
	formFieldValue->setFont (Font(11));
	formFieldValue->applyFontToAllText (Font(11));
	elm = 0;
    //[/UserPreSize]

    setSize (220, 120);

    //[Constructor] You can add your own custom stuff here..
    //[/Constructor]
}

formElement::~formElement()
{
    //[Destructor_pre]. You can add your own custom destruction code here..
    //[/Destructor_pre]

    deleteAndZero (groupComponent);
    deleteAndZero (formFieldType);
    deleteAndZero (formFieldName);
    deleteAndZero (formFieldValue);
    deleteAndZero (removeFormElement);

    //[Destructor]. You can add your own custom destruction code here..
    //[/Destructor]
}

//==============================================================================
void formElement::paint (Graphics& g)
{
    //[UserPrePaint] Add your own custom painting code here..
    //[/UserPrePaint]

    //[UserPaint] Add your own custom painting code here..
    //[/UserPaint]
}

void formElement::resized()
{
    groupComponent->setBounds (0, 0, 216, 120);
    formFieldType->setBounds (8, 14, 176, 16);
    formFieldName->setBounds (8, 38, 200, 16);
    formFieldValue->setBounds (8, 62, 200, 50);
    removeFormElement->setBounds (192, 16, 16, 16);
    //[UserResized] Add your own custom resize handling here..
    //[/UserResized]
}

void formElement::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
{
    //[UsercomboBoxChanged_Pre]
    //[/UsercomboBoxChanged_Pre]

    if (comboBoxThatHasChanged == formFieldType)
    {
        //[UserComboBoxCode_formFieldType] -- add your combo box handling code here..
		if (formFieldType->getText() ==  T("ASK - Input"))
		{
			formFieldName->setEnabled(true);
			formFieldValue->setEnabled(false);
		}
		else if (formFieldType->getText() ==  T("File"))
		{
			formFieldName->setEnabled(true);
			formFieldValue->setEnabled(false);
		}
		else
		{
			formFieldName->setEnabled(true);
			formFieldValue->setEnabled(true);
		}
        //[/UserComboBoxCode_formFieldType]
    }

    //[UsercomboBoxChanged_Post]
    //[/UsercomboBoxChanged_Post]
}

void formElement::buttonClicked (Button* buttonThatWasClicked)
{
    //[UserbuttonClicked_Pre]
    //[/UserbuttonClicked_Pre]

    if (buttonThatWasClicked == removeFormElement)
    {
        //[UserButtonCode_removeFormElement] -- add your button handler code here..
		parent->removeElement (index);
        //[/UserButtonCode_removeFormElement]
    }

    //[UserbuttonClicked_Post]
    //[/UserbuttonClicked_Post]
}



//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
void formElement::setRemove ()
{
	shouldBeRemoved = true;
}

bool formElement::getRemove ()
{
	return (shouldBeRemoved);
}

void formElement::setIndex (int i)
{
	index = i;
}

XmlElement *formElement::getXmlElement()
{
	setXmlData();
	return (elm);
}

void formElement::setXmlData (XmlElement *e)
{
	if (e)
	{
		formFieldName->setText (e->getStringAttribute (T("fieldName"), String::empty));
		formFieldValue->setText (e->getStringAttribute (T("fieldValue"), String::empty));
		formFieldType->setText (e->getStringAttribute (T("fieldType"), String::empty));
	}
}

void formElement::setXmlData()
{
	if (!elm)
	{
		elm = new XmlElement (T("HTMLformElement"));
	}
	else
	{
		deleteAndZero (elm);
		elm = new XmlElement (T("HTMLformElement"));
	}

	elm->setAttribute (T("fieldType"), formFieldType->getText());
	elm->setAttribute (T("fieldName"), formFieldName->getText());
	elm->setAttribute (T("fieldValue"), formFieldValue->getText());
}
//[/MiscUserCode]


//==============================================================================
#if 0
/*  -- Jucer information section --

    This is where the Jucer puts all of its metadata, so don't change anything in here!

BEGIN_JUCER_METADATA

<JUCER_COMPONENT documentType="Component" className="formElement" componentName="formElement"
                 parentClasses="public Component" constructorParams="KetonalFormEditor *_p, int i"
                 variableInitialisers="" snapPixels="8" snapActive="1" snapShown="1"
                 overlayOpacity="0.330000013" fixedSize="1" initialWidth="220"
                 initialHeight="120">
  <BACKGROUND backgroundColour="aefaff"/>
  <GROUPCOMPONENT name="new group" id="14f4c69c00768367" memberName="groupComponent"
                  virtualName="" explicitFocusOrder="0" pos="0 0 216 120" title="Element"
                  textpos="36"/>
  <COMBOBOX name="Field Type" id="12b85d6517a3d154" memberName="formFieldType"
            virtualName="" explicitFocusOrder="0" pos="8 14 176 16" tooltip="Field Type"
            editable="0" layout="33" items="Input&#10;ASK - Input&#10;File" textWhenNonSelected=""
            textWhenNoItems="(no choices)"/>
  <TEXTEDITOR name="Field Name" id="70428fbf742ec6fb" memberName="formFieldName"
              virtualName="" explicitFocusOrder="0" pos="8 38 200 16" tooltip="Field Name"
              bkgcol="beffffff" shadowcol="0" initialText="name" multiline="0"
              retKeyStartsLine="0" readonly="0" scrollbars="1" caret="1" popupmenu="1"/>
  <TEXTEDITOR name="Field Value" id="2a39893bbe5e43f1" memberName="formFieldValue"
              virtualName="" explicitFocusOrder="0" pos="8 62 200 50" tooltip="Field Value"
              bkgcol="beffffff" shadowcol="0" initialText="value" multiline="1"
              retKeyStartsLine="1" readonly="0" scrollbars="1" caret="1" popupmenu="1"/>
  <IMAGEBUTTON name="Remove Element" id="2fd7514cea1c44da" memberName="removeFormElement"
               virtualName="" explicitFocusOrder="0" pos="192 16 16 16" tooltip="Remove Element"
               buttonText="new button" connectedEdges="0" needsCallback="1"
               radioGroupId="0" keepProportions="1" resourceNormal="listremove_png"
               opacityNormal="0.578616381" colourNormal="0" resourceOver="listremove_png"
               opacityOver="1" colourOver="0" resourceDown="listremove_png"
               opacityDown="1" colourDown="38f7ff76"/>
</JUCER_COMPONENT>

END_JUCER_METADATA
*/
#endif

//==============================================================================
// Binary resources - be careful not to edit any of these sections!

// JUCER_RESOURCE: listremove_png, 858, "C:\process-stop.png"
static const unsigned char resource_formElement_listremove_png[] = { 137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,16,0,0,0,16,8,6,0,0,0,31,243,255,97,0,0,0,1,115,82,71,66,0,174,206,28,233,0,0,0,
6,98,75,71,68,0,255,0,255,0,255,160,189,167,147,0,0,0,9,112,72,89,115,0,0,11,19,0,0,11,19,1,0,154,156,24,0,0,0,7,116,73,77,69,7,216,6,2,19,38,32,241,32,183,12,0,0,2,218,73,68,65,84,56,203,141,147,79,104,
92,85,20,135,191,123,222,191,121,73,108,98,146,54,17,132,102,32,200,100,33,141,104,101,40,165,4,92,204,4,166,181,237,170,27,131,88,236,66,90,112,97,160,155,162,161,66,197,42,149,174,164,82,55,86,180,40,
226,46,11,7,134,186,170,139,74,99,18,76,70,108,11,13,164,36,4,147,154,121,239,190,55,239,221,235,98,72,136,174,60,112,224,156,197,249,113,126,156,239,192,127,226,3,224,67,254,127,168,189,205,39,160,70,
171,213,207,139,229,242,57,155,101,88,99,140,53,198,70,113,108,215,22,23,211,63,235,245,55,166,225,135,189,51,206,78,113,21,228,133,201,201,27,47,79,78,190,237,61,121,66,33,138,8,162,72,5,173,150,244,
104,45,195,163,163,94,100,204,233,87,86,86,230,235,176,244,47,129,143,65,74,181,218,23,47,77,76,156,205,154,77,108,146,96,180,198,38,73,39,181,198,108,108,48,92,42,57,235,219,219,167,143,172,175,255,86,
135,101,0,249,20,100,236,196,137,155,135,202,229,183,210,197,69,10,99,99,244,86,42,144,36,144,36,184,97,200,254,169,41,252,193,65,236,210,18,229,163,71,125,255,224,193,239,62,130,26,128,24,168,142,79,
76,188,153,204,207,99,162,136,253,83,83,60,91,173,50,112,242,36,174,8,67,23,46,176,239,216,49,6,207,156,65,178,12,103,97,129,215,142,31,247,35,248,30,64,0,143,167,79,49,173,22,54,142,249,235,214,45,48,
134,103,42,21,134,46,94,36,40,22,177,90,243,247,237,219,184,121,142,147,101,244,106,141,21,241,0,92,64,76,28,147,111,110,98,86,86,88,187,123,23,175,167,135,125,167,78,225,143,140,128,49,108,94,190,76,
187,209,64,133,33,226,56,168,52,69,68,44,198,32,128,106,175,173,161,239,223,135,173,45,60,223,39,189,119,15,84,231,194,54,142,225,193,3,252,66,1,71,107,100,107,11,146,4,37,98,119,44,168,246,227,199,136,
181,136,235,18,142,143,51,112,233,82,7,18,99,144,238,110,122,175,92,193,239,239,199,11,2,28,145,29,1,179,43,160,68,80,142,131,227,121,12,93,187,134,42,20,48,205,38,241,244,52,196,49,206,200,8,221,231,
207,227,120,30,142,235,98,148,66,41,181,187,193,207,171,65,240,187,119,224,0,88,75,50,55,71,190,186,202,246,204,12,246,209,35,242,235,215,65,107,204,242,50,74,4,250,250,248,101,99,3,63,203,190,222,69,
249,42,12,191,90,171,53,158,123,248,176,228,198,49,65,87,23,126,87,23,65,24,226,250,62,214,90,218,90,147,138,240,107,24,178,112,231,206,77,180,62,247,30,24,7,224,39,216,46,54,155,63,246,31,62,252,122,
95,154,246,171,142,71,176,22,147,231,100,237,54,153,8,127,12,12,48,215,104,124,121,35,142,223,249,166,67,178,85,123,158,106,232,8,148,102,42,149,175,198,194,240,121,215,117,113,60,15,37,66,156,101,172,
231,57,245,217,217,111,223,111,181,222,141,33,2,18,32,221,43,224,1,133,10,20,15,193,139,57,184,22,28,213,129,197,56,160,63,131,217,8,52,144,2,6,224,31,57,148,54,199,194,149,131,103,0,0,0,0,73,69,78,68,
174,66,96,130,0,0};

const char* formElement::listremove_png = (const char*) resource_formElement_listremove_png;
const int formElement::listremove_pngSize = 858;
